package JLB_Chapter_09;

import java.util.Random;
import java.util.Scanner;

public class code_09_12 {
    public static void main(String[] args) {
        System.out.println("----模拟抢红包----");
        Scanner in = new Scanner(System.in);
        System.out.println("请输入要装入红包的总金额（元）");
        double total = in.nextDouble();
        System.out.println("请输入红包的个数（个）");
        int bagsNum = in.nextInt();
        double min = 0.01;
        Random random = new Random();
        for(int i = 1; i < bagsNum; i++) {
            double max = total - (bagsNum - i) * min;
            double bound = max - min;
            double safe = (double) random.nextInt((int) (bound * 100)) / 100;
            double money = safe + min;
            total = total - money;
            System.out.println("第" + i + "个红包" + String.format("%.2f", money) + "元");
        }
        System.out.println("第" + bagsNum + "个红包" + String.format("%.2f", total) + "元");
        in.close();
    }
}
